from flask import g
from functools import wraps


def login_required(func):
    """
    强制登录装饰器
    """
    @wraps(func)
    def warpper(*args, **kwargs):
        if g.user_id is not None:
            return func(*args, **kwargs)
        return {"code": 401, "message": "fail"}
    return warpper



